﻿using System;
using System.Collections.Generic;

using Caliburn.Micro;

namespace Cooking.Client.CaliburnExtensions
{
    public abstract class ComplexCoroutine : IResult
    {
        public event EventHandler<ResultCompletionEventArgs> Completed = delegate { };

        public void Execute(ActionExecutionContext context)
        {
            var result = new SequentialResult(OnExecute().GetEnumerator());
            result.Completed += (obj, sender) => Completed(this, new ResultCompletionEventArgs());
            result.Execute(context);
        }

        protected abstract IEnumerable<IResult> OnExecute();
    }
}